/**
 * device_add
 * 
 * 功能：
 * 	1、查询设备号：device_id 
 * 	2、表单拦截：
 */

window.onload = function(){

	//执行方法区：
	find_DeviceId();//查询设备号 device_id
	
	
	//1、查询设备号：device_id 
	function find_DeviceId(){
		var dId = document.getElementById("dId");
		
		//ajax给servlet传参
		var xhr = new XMLHttpRequest();
		
		xhr.onreadystatechange = function(){
			if(xhr.readyState==4){
				if(xhr.status>=200 && xhr.status<300 || xhr.status==304){
					var re = xhr.responseText;
					if(re!=""){
						if(re>0){//设备数量大于0就正常显示
							dId.value = re;
							dId.style.color = "white";
						}else{//设备数量小于等于0，为1
							dId.value = 0;
							dId.style.color = "red";
						}
					}else{
						dId.value = 0;
						dId.style.color = "red";
						console.log("servlet:设备空空如也！");
					}
				}else{
					console.log("ajax:请求失败！");
				}
			}
		}
		xhr.open("post","../device_FindServlet",true);
		xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
		xhr.send("find=dId");
		
	}
//2、表单拦截：
	
}